-
Notifications
You must be signed in to change notification settings - Fork 1.9k
GH-4251 Add the capability to parse required variables from templates to TemplateRenderer
#4252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…TemplateRenderer` to parse the required variables from the template. Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
# Conflicts: # spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/SystemPromptTemplateTests.java
Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
Hi @sunyuhan1998, Could you please rebase against main and also add the following logic: not all implementations may support retrieving variable names. As a consequence, could you make the new method throw NotSupportedException and make it |
# Conflicts: # spring-ai-template-st/src/test/java/org/springframework/ai/template/st/StTemplateRendererTests.java
…to handle cases where subclasses do not support this method. Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
Thank you very much for your review. I agree with your comments. I have merged the code from the main branch and adjusted the |
That's the one I meant, sorry. However, the more I look at this, the more I think this may be a rabbit hole, especially for the case you want to support: what about nested properties? what about method invocations on objects? what about x... ? |
As mentioned in the issue,
TemplateRenderer
currently only supports rendering templates. The ability to also parse and extract the required variables from a given template would be highly beneficial, especially for proactively validating template correctness. This PR implements that capability.Specifically, it:
Adds a
getRequiredVariables
method toTemplateRenderer
to extract the variable names required by the template;Includes corresponding unit tests to ensure correctness and stability.
Fixes #4251